<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/corelib/plugin/qpluginloader.cpp -->
<head>
  <title>Qt 4.3: QPluginLoader Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QPluginLoader Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1>
<p>The QPluginLoader class loads a plugin at run-time. <a href="#details">More...</a></p>
<pre> #include &lt;QPluginLoader&gt;</pre><p>Inherits <a href="qobject.html">QObject</a>.</p>
<p><b>Note:</b> All the functions in this class are <a href="threads.html#reentrant">reentrant</a>.</p>
<ul>
<li><a href="qpluginloader-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="properties"></a>
<h3>Properties</h3>
<ul>
<li><div class="fn"/><b><a href="qpluginloader.html#fileName-prop">fileName</a></b> : QString</li>
</ul>
<ul>
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qpluginloader.html#QPluginLoader">QPluginLoader</a></b> ( QObject * <i>parent</i> = 0 )</li>
<li><div class="fn"/><b><a href="qpluginloader.html#QPluginLoader-2">QPluginLoader</a></b> ( const QString &amp; <i>fileName</i>, QObject * <i>parent</i> = 0 )</li>
<li><div class="fn"/><b><a href="qpluginloader.html#dtor.QPluginLoader">~QPluginLoader</a></b> ()</li>
<li><div class="fn"/>QString <b><a href="qpluginloader.html#errorString">errorString</a></b> () const</li>
<li><div class="fn"/>QString <b><a href="qpluginloader.html#fileName-prop">fileName</a></b> () const</li>
<li><div class="fn"/>QObject * <b><a href="qpluginloader.html#instance">instance</a></b> ()</li>
<li><div class="fn"/>bool <b><a href="qpluginloader.html#isLoaded">isLoaded</a></b> () const</li>
<li><div class="fn"/>bool <b><a href="qpluginloader.html#load">load</a></b> ()</li>
<li><div class="fn"/>void <b><a href="qpluginloader.html#fileName-prop">setFileName</a></b> ( const QString &amp; <i>fileName</i> )</li>
<li><div class="fn"/>bool <b><a href="qpluginloader.html#unload">unload</a></b> ()</li>
</ul>
<ul>
<li><div class="fn"/>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<a name="static-public-members"></a>
<h3>Static Public Members</h3>
<ul>
<li><div class="fn"/>QObjectList <b><a href="qpluginloader.html#staticInstances">staticInstances</a></b> ()</li>
</ul>
<ul>
<li><div class="fn"/>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QPluginLoader class loads a plugin at run-time.</p>
<p>QPluginLoader provides access to a <a href="plugins-howto.html">Qt plugin</a>. A Qt plugin is stored in a shared library (a DLL) and offers these benefits over shared libraries accessed using <a href="qlibrary.html">QLibrary</a>:</p>
<ul>
<li>QPluginLoader checks that a plugin is linked against the same version of Qt as the application.</li>
<li>QPluginLoader provides direct access to a root component object (<a href="qpluginloader.html#instance">instance</a>()), instead of forcing you to resolve a C function manually.</li>
</ul>
<p>An instance of a QPluginLoader object operates on a single shared library file, which we call a plugin. It provides access to the functionality in the plugin in a platform-independent way. To specify which plugin to load, either pass a file name in the constructor or set it with <a href="qpluginloader.html#fileName-prop">setFileName</a>().</p>
<p>The most important functions are <a href="qpluginloader.html#load">load</a>() to dynamically load the plugin file, <a href="qpluginloader.html#isLoaded">isLoaded</a>() to check whether loading was successful, and <a href="qpluginloader.html#instance">instance</a>() to access the root component in the plugin. The <a href="qpluginloader.html#instance">instance</a>() function implicitly tries to load the plugin if it has not been loaded yet. Multiple instances of QPluginLoader can be used to access the same physical plugin.</p>
<p>Once loaded, plugins remain in memory until the application terminates. You can attempt to unload a plugin using <a href="qpluginloader.html#unload">unload</a>(), but if other instances of QPluginLoader are using the same library, the call will fail, and unloading will only happen when every instance has called <a href="qpluginloader.html#unload">unload</a>().</p>
<p>In order to speed up loading and validation of plugins, some of the information that is collected during loading is cached in persistent memory (through <a href="qsettings.html">QSettings</a>). For instance, the result of a load operation (e.g&#x2e; succeeded or failed) is stored in the cache, so that subsequent load operations don't try to load an invalid plugin. However, if the &quot;last modified&quot; timestamp of a plugin has changed, the plugin's cache entry is invalidated and the plugin is reloaded regardless of the values in the cache entry. The cache entry is then updated with the new result of the load operation.</p>
<p>This also means that the timestamp must be updated each time the plugin or any dependent resources (such as a shared library) is updated, since the dependent resources might influence the result of loading a plugin.</p>
<p>See <a href="plugins-howto.html">How to Create Qt Plugins</a> for more information about how to make your application extensible through plugins.</p>
<p>See also <a href="qlibrary.html">QLibrary</a> and <a href="tools-plugandpaint.html">Plug &amp; Paint Example</a>.</p>
<hr />
<h2>Property Documentation</h2>
<h3 class="fn"><a name="fileName-prop"></a>fileName : <a href="qstring.html">QString</a></h3>
<p>This property holds the file name of the plugin.</p>
<p>To be loadable, the file's suffix must be a valid suffix for a loadable library in accordance with the platform, e.g&#x2e; <tt>.so</tt> on Unix, <tt>.dylib</tt> on Mac OS X, and <tt>.dll</tt> on Windows. The suffix can be verified with <a href="qlibrary.html#isLibrary">QLibrary::isLibrary</a>().</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>QString fileName () const</b></li>
<li><div class="fn"/><b>void setFileName ( const QString &amp; <i>fileName</i> )</b></li>
</ul>
<p>See also <a href="qpluginloader.html#load">load</a>().</p>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QPluginLoader"></a>QPluginLoader::QPluginLoader ( <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
<p>Constructs a plugin loader with the given <i>parent</i>.</p>
<h3 class="fn"><a name="QPluginLoader-2"></a>QPluginLoader::QPluginLoader ( const <a href="qstring.html">QString</a> &amp; <i>fileName</i>, <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
<p>Constructs a plugin loader with the given <i>parent</i> that will load the plugin specified by <i>fileName</i>.</p>
<p>To be loadable, the file's suffix must be a valid suffix for a loadable library in accordance with the platform, e.g&#x2e; <tt>.so</tt> on Unix, - <tt>.dylib</tt> on Mac OS X, and <tt>.dll</tt> on Windows. The suffix can be verified with <a href="qlibrary.html#isLibrary">QLibrary::isLibrary</a>().</p>
<p>See also <a href="qpluginloader.html#fileName-prop">setFileName</a>().</p>
<h3 class="fn"><a name="dtor.QPluginLoader"></a>QPluginLoader::~QPluginLoader ()</h3>
<p>Destroys the <a href="qpluginloader.html">QPluginLoader</a> object.</p>
<p>Unless <a href="qpluginloader.html#unload">unload</a>() was called explicitly, the plugin stays in memory until the application terminates.</p>
<p>See also <a href="qpluginloader.html#isLoaded">isLoaded</a>() and <a href="qpluginloader.html#unload">unload</a>().</p>
<h3 class="fn"><a name="errorString"></a><a href="qstring.html">QString</a> QPluginLoader::errorString () const</h3>
<p>Returns a text string with the description of the last error that occurred.</p>
<p>This function was introduced in Qt 4.2.</p>
<h3 class="fn"><a name="instance"></a><a href="qobject.html">QObject</a> * QPluginLoader::instance ()</h3>
<p>Returns the root component object of the plugin. The plugin is loaded if necessary. The function returns 0 if the plugin could not be loaded or if the root component object could not be instantiated.</p>
<p>If the root component object was destroyed, calling this function creates a new instance.</p>
<p>The root component, returned by this function, is not deleted when the <a href="qpluginloader.html">QPluginLoader</a> is destroyed.</p>
<p>The component object is a <a href="qobject.html">QObject</a>. Use <a href="qobject.html#qobject_cast">qobject_cast</a>() to access interfaces you are interested in.</p>
<p>See also <a href="qpluginloader.html#load">load</a>().</p>
<h3 class="fn"><a name="isLoaded"></a>bool QPluginLoader::isLoaded () const</h3>
<p>Returns true if the plugin is loaded; otherwise returns false.</p>
<p>See also <a href="qpluginloader.html#load">load</a>().</p>
<h3 class="fn"><a name="load"></a>bool QPluginLoader::load ()</h3>
<p>Loads the plugin and returns true if the plugin was loaded successfully; otherwise returns false. Since <a href="qpluginloader.html#instance">instance</a>() always calls this function before resolving any symbols it is not necessary to call it explicitly. In some situations you might want the plugin loaded in advance, in which case you would use this function.</p>
<p>See also <a href="qpluginloader.html#unload">unload</a>().</p>
<h3 class="fn"><a name="staticInstances"></a><a href="qobject.html#QObjectList-typedef">QObjectList</a> QPluginLoader::staticInstances ()&nbsp;&nbsp;<tt> [static]</tt></h3>
<p>Returns a list of static plugin instances (root components) held by the plugin loader.</p>
<h3 class="fn"><a name="unload"></a>bool QPluginLoader::unload ()</h3>
<p>Unloads the plugin and returns true if the plugin could be unloaded; otherwise returns false.</p>
<p>This happens automatically on application termination, so you shouldn't normally need to call this function.</p>
<p>If other instances of <a href="qpluginloader.html">QPluginLoader</a> are using the same plugin, the call will fail, and unloading will only happen when every instance has called unload().</p>
<p><b>Warning:</b> The root component of a plugin, returned by the <a href="qpluginloader.html#instance">instance</a>() function, becomes invalid once the plugin is unloaded. Delete the root component before unloading the plugin. Attempting to access members of invalid root components will in most cases result in a segmentation fault.</p>
<p>See also <a href="qpluginloader.html#instance">instance</a>() and <a href="qpluginloader.html#load">load</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
